/*
 * Copyright (c) 2019. ascend 版权所有禁止转载。
 */

package cn.edu.zua.demo17.service;

import cn.edu.zua.demo17.entity.TestUserEntity;
import cn.edu.zua.demo17.jpa.TestUserJpa;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * 说明：
 *
 * @author ascend
 * 2019/1/29 16:45
 */
@Service
public class TestUserServiceImpl implements UserDetailsService {
    private TestUserJpa userJpa;


    @Autowired
    public TestUserServiceImpl(TestUserJpa userJpa) {
        this.userJpa = userJpa;
    }

    @Override
    public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {
        TestUserEntity userEntity = userJpa.findByUserName(userName);
        if (userEntity == null) {
            throw new UsernameNotFoundException("未查询到用户:" + userName + "信息");
        }
        System.out.println("userEntity = " + userEntity);
        return userEntity;
    }
}
